package com.zhouheng.springbootmultithreading.module.bankaccount.atm;

import com.zhouheng.springbootmultithreading.module.bankaccount.entity.BankAccountVo;
import com.zhouheng.springbootmultithreading.common.utils.HttpRequestUtils;
import com.zhouheng.springbootmultithreading.common.utils.JsonUtil;

public class AtmWithdrawMoney extends Thread {

    private String atmName;
    private String url;
    private String account;
    private String password;
    private Double money;

    public AtmWithdrawMoney(String atmName, String url, String account, String password, Double money){
        this.atmName = atmName;
        this.url = url;
        this.account = account;
        this.password = password;
        this.money = money;
    }

    @Override
    public void run() {
        this.withdrawMoney();
    }

    /**
     * 这里是run方法调用的方法一定要是public的，是private就不能执行run方法
     *
     * @author 周恒
     * @date 20190118 16:53:55
     * @since v1.0
     */
    public void withdrawMoney()  {
        BankAccountVo bankAccountVo = new BankAccountVo();
        bankAccountVo.setAccount(account);
        bankAccountVo.setPassword(password);
        bankAccountVo.setMoney(money);
        String param = JsonUtil.toJson(bankAccountVo);
        try{
            String result = HttpRequestUtils.httpPostString(url, param);
            System.out.println(System.currentTimeMillis() +" "+ atmName+"取款:"+money+" 取款后余额为:"+result);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

}